<?php
require_once "class_Main.php";
	
	class Admin extends Main{
	
		protected $adm_con;
		private $ord_opt = array ('Order A-Z'=>'title ASC', 'Order Z-A'=>'title DESC', 'Order 0-9'=>'issue_date ASC', 'Order 9-0'=>'issue_date DESC');
		
		public function __construct(){
			$this->adm_con = parent::connect();
		}
		
		public function product_list($ord){
			$select = "SELECT id, title, category FROM store ORDER BY $ord";
			$result = mysql_query($select, $this->adm_con);
			$i=0;
			while($list=mysql_fetch_array($result, MYSQL_ASSOC)){
				$srch = array('1', '2', '3');
				$replace = array('Книги', 'Периодика' , 'Фото');
				$refurbished = str_replace($srch, $replace, $list['category']);
				$list['cat_string'] = $refurbished;
				$all[$i] = $list;
				$i++;
			}
			return $all;
		}
		
		public function filter($ord){
		$options="";
			foreach ($this->ord_opt as $key=>$value){
			if (preg_match("/^$value$/", $ord)){	
					$options .= "<option value=\"$value\" selected=\"selected\">$key</option>";
				}
				else{
					$options .= "<option value=\"$value\">$key</option>";
				}
			}
			return $options;
		}
		
		public function del ($id){										// Доделать !!!
			$del = "DELETE FROM store WHERE id='.(int)$id.'";
			mysql_query ($del, $this->adm_con);
			echo "shlapa";
		}

		public function save($data){
			// from here choose which method to choose from the ones below.
			//check code ignitor
		}

		private function add(){
			echo 'added';
		}

		private function upd(){
			echo 'updated';
		}
	}
?>